﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.Entities_DAL
{
    public class Chucvu_DAL: BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            var sql = @"SELECT * FROM CHUC_VU";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM CHUC_VU WHERE MA_CV = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (CHUC_VU)obj;
            string sql = @"set dateformat dmy;INSERT INTO CHUC_VU(MA_CV, TEN_CV) VALUES('{0}',N'{1}') ";
            sql = string.Format(sql, o.MA_CV, o.TEN_CV);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (CHUC_VU)obj;
            string sql = @"set dateformat dmy;UPDATE CHUC_VU SET TEN_CV=N'{1}' where MA_CV='{0}'";
            sql = string.Format(sql, o.MA_CV, o.TEN_CV);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Select_max()
        {
            var sql = @"SELECT max(MA_CV) as id FROM CHUC_VU";
            return ExecuteQuery(sql);

            
        }

        public string Select_count()
        {
            string sql = @"SELECT count(MA_CV) as id FROM CHUC_VU";
            var tb = ExecuteQuery(sql);
            return tb.Rows.Count > 0 ? tb.Rows[0]["id"] + "" : "0";
        }
    }
}
